package com.jackeysun.app_util

import android.annotation.SuppressLint
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.jackeysun.app_util.databinding.ActivityMain2Binding
import com.jackeysun.app_util.databinding.ItemViewBinding
import com.jackeysun.util.DividerItemDecoration

class MainActivity2 : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = ActivityMain2Binding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.rv.layoutManager = GridLayoutManager(this, 4)
        binding.rv.adapter = DividerAdapter()
        binding.rv.addItemDecoration(DividerItemDecoration(spanCount = 4))
    }

}

class DividerAdapter : RecyclerView.Adapter<DividerViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DividerViewHolder {
        return DividerViewHolder(
            ItemViewBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: DividerViewHolder, position: Int) {
        holder.mBinding.tv.text = "第 $position 项"
    }

    override fun getItemCount(): Int = 100

}

class DividerViewHolder(var mBinding: ItemViewBinding) : RecyclerView.ViewHolder(mBinding.root)